# coding:utf-8
"""
    @project: selenium_utls
    @Author：caicaizi
    @file： yaml_util.py
    @date：2024/1/13 22:41
"""
import yaml


def read_yaml(path):
    """
    读取yaml文件
    :param path: yaml文件路径
    :return: yaml数据（字典类型）
    """
    with open(path, encoding='utf-8', mode='r') as f:
        data = yaml.load(stream=f, Loader=yaml.FullLoader)
        return data


def write_yaml(path, data):
    """
    写入yaml文件
    :param path: yaml文件路径
    :param data: 要写入数据
    """
    with open(path, encoding='utf-8', mode='a+') as f:
        yaml.dump(data, stream=f, allow_unicode=True)


def clear_yaml(path):
    """
    清空yaml文件
    :param path: yaml文件路径
    """
    with open(path, encoding='utf-8', mode='w') as f:
        f.truncate()